import {BasicColumn} from '/@/components/Table';
import {FormSchema} from '/@/components/Table';
import { rules} from '/@/utils/helper/validator';
import { render } from '/@/utils/common/renderUtils';
import {h} from "vue";
//列表数据
export const columns: BasicColumn[] = [
  /*{
    title: '数据终端id',
    align:"center",
    dataIndex: 'id'
  },*/
   {
    title: '数据终端编号',
    align:"center",
    dataIndex: 'no'
   },
   {
    title: 'imei',
    align:"center",
    dataIndex: 'imei'
   },

  {
    title: '数据终端名称',
    align:"center",
    dataIndex: 'name'
  },
  {
    title: '温度℃',
    align:"center",
    dataIndex: 'temperature'
  },
  {
    title: '湿度%',
    align:"center",
    dataIndex: 'humidity'
  },
  {
    title: '电池电压v',
    align:"center",
    dataIndex: 'voltage'
  },
   {
    title: '通信状态',
    align:"center",
    dataIndex: 'lastConnectTime',
     customRender:({ text }) => {

       // 判断是否显示红球
       let color = '#ff0000';
       let labelText = '未激活';
       if(text == null){
          color = '#666666';
        }else{
          const nowDate = new Date();
          const lastTime = new Date(text)
          if(nowDate.getTime() - lastTime.getTime() > (1.5 * 60 * 60 * 1000)){
            labelText = '离线';
          }else{
            color = '#00ff00';
            labelText = '在线';
          }
        }
         // 创建一个红球的 VNode
         const redBall = h('div', {
           style: {
             background: color,
             width: '12px',
             height: '12px',
             borderRadius: '50%',
             display: 'inline-block',
             margin: '0 5px'
           }
         });
         // 创建一个包含文本和红球的父元素 VNode
         return h('div', [
           h('span', labelText), // 使用 h 函数来创建 span VNode
           redBall // 如果要显示红球，则添加它到数组中
         ]);
       }
   },
  /* {
    title: 'NB通信信号强度',
    align:"center",
    dataIndex: 'nbIotSign'
   },
   {
    title: '电压强度',
    align:"center",
    dataIndex: 'voltage'
   },*/
   {
    title: '最后一次通信时间',
    align:"center",
    dataIndex: 'lastConnectTime'
   },
  {
    title: '组织编号',
    align:"center",
    dataIndex: 'sysOrgCode'
  },
  {
    title: '传感器数量',
    align:"center",
    dataIndex: 'deviceNum'
  },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: "数据终端名称",
    field: 'name',
    component: 'JInput',
    //colProps: {span: 6},
  },
  {
    label: "数据终端编号",
    field: 'no',
    component: 'Input',
    //colProps: {span: 6},
  },
  {
    label: "imei",
    field: 'imei',
    component: 'Input',
    //colProps: {span: 6},
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: '数据终端名称',
    field: 'name',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
          return [
                 { required: true, message: '请输入设备名称!'},
          ];
     },
  },
  {
    label: '32位终端编号',
    field: 'no',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入32位终端号!',pattern: /^[0-9a-fA-F]{32}$/},
        {...rules.duplicateCheckRule('terminal', 'no',model,schema)[0]},
      ];
    },
  },
  {
    label: '15位imei',
    field: 'imei',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: '请输入15位imei号!',pattern: /^\d{15}$/},
        {...rules.duplicateCheckRule('terminal', 'imei',model,schema)[0]},
      ];
    },
  },
  /*{
    label: '通信状态',
    field: 'communicationStatus',
    component: 'Input',
    dynamicRules: ({model,schema}) => {
      return [
        { required: true, message: 'communicationStatus!'},
      ];
    },
  },*/

	// TODO 主键隐藏字段，目前写死为ID
	{
	  label: '',
	  field: 'id',
	  component: 'Input',
	  show: false
	},
];



/**
* 流程表单调用这个方法获取formSchema
* @param param
*/
export function getBpmFormSchema(_formData): FormSchema[]{
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
